Packages

library(dplyr)
package 㤼㸱dplyr㤼㸲 was built under R version 4.0.3
Attaching package: 㤼㸱dplyr㤼㸲

The following objects are masked from 㤼㸱package:stats㤼㸲:

    filter, lag

The following objects are masked from 㤼㸱package:base㤼㸲:

    intersect, setdiff, setequal, union
library(ggcorrplot)
package 㤼㸱ggcorrplot㤼㸲 was built under R version 4.0.5Loading required package: ggplot2
package 㤼㸱ggplot2㤼㸲 was built under R version 4.0.5
library(ggpubr)
package 㤼㸱ggpubr㤼㸲 was built under R version 4.0.3Registered S3 method overwritten by 'data.table':
  method           from
  print.data.table     
library(patchwork)
package 㤼㸱patchwork㤼㸲 was built under R version 4.0.5
# library("here")
# library("bookdown")
# library("downloadthis")
library(vegan)
package 㤼㸱vegan㤼㸲 was built under R version 4.0.5Loading required package: permute
Loading required package: lattice
This is vegan 2.5-7
library(plyr)
---------------------------------------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
---------------------------------------------------------------------------------------------------------

Attaching package: 㤼㸱plyr㤼㸲

The following object is masked from 㤼㸱package:ggpubr㤼㸲:

    mutate

The following objects are masked from 㤼㸱package:dplyr㤼㸲:

    arrange, count, desc, failwith, id, mutate, rename, summarise, summarize
library(e1071)
package 㤼㸱e1071㤼㸲 was built under R version 4.0.3
library(tidyverse)
package 㤼㸱tidyverse㤼㸲 was built under R version 4.0.3Registered S3 methods overwritten by 'dbplyr':
  method         from
  print.tbl_lazy     
  print.tbl_sql      
-- Attaching packages ------------------------------------------------------------------ tidyverse 1.3.0 --
√ tibble  3.0.4     √ purrr   0.3.4
√ tidyr   1.1.2     √ stringr 1.4.0
√ readr   1.4.0     √ forcats 0.5.0
package 㤼㸱tibble㤼㸲 was built under R version 4.0.3package 㤼㸱tidyr㤼㸲 was built under R version 4.0.3package 㤼㸱readr㤼㸲 was built under R version 4.0.3package 㤼㸱purrr㤼㸲 was built under R version 4.0.5-- Conflicts --------------------------------------------------------------------- tidyverse_conflicts() --
x plyr::arrange()   masks dplyr::arrange()
x purrr::compact()  masks plyr::compact()
x plyr::count()     masks dplyr::count()
x plyr::failwith()  masks dplyr::failwith()
x dplyr::filter()   masks stats::filter()
x plyr::id()        masks dplyr::id()
x dplyr::lag()      masks stats::lag()
x plyr::mutate()    masks ggpubr::mutate(), dplyr::mutate()
x plyr::rename()    masks dplyr::rename()
x plyr::summarise() masks dplyr::summarise()
x plyr::summarize() masks dplyr::summarize()
library(viridis)
Loading required package: viridisLite
library(GGally)
package 㤼㸱GGally㤼㸲 was built under R version 4.0.5Registered S3 method overwritten by 'GGally':
  method from   
  +.gg   ggplot2
library(ggrepel)
package 㤼㸱ggrepel㤼㸲 was built under R version 4.0.3
library(ggordiplots)
Loading required package: glue

Attaching package: 㤼㸱glue㤼㸲

The following object is masked from 㤼㸱package:dplyr㤼㸲:

    collapse


Attaching package: 㤼㸱ggordiplots㤼㸲

The following object is masked _by_ 㤼㸱.GlobalEnv㤼㸲:

    gg_ordisurf
library(readr)
library(RColorBrewer)
package 㤼㸱RColorBrewer㤼㸲 was built under R version 4.0.5
library(oce) 
package 㤼㸱oce㤼㸲 was built under R version 4.0.5Loading required package: gsw
package 㤼㸱gsw㤼㸲 was built under R version 4.0.5
library(plotly)
package 㤼㸱plotly㤼㸲 was built under R version 4.0.5Registered S3 methods overwritten by 'htmltools':
  method               from         
  print.html           tools:rstudio
  print.shiny.tag      tools:rstudio
  print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
  method           from         
  print.htmlwidget tools:rstudio

Attaching package: 㤼㸱plotly㤼㸲

The following objects are masked from 㤼㸱package:plyr㤼㸲:

    arrange, mutate, rename, summarise

The following object is masked from 㤼㸱package:ggplot2㤼㸲:

    last_plot

The following object is masked from 㤼㸱package:stats㤼㸲:

    filter

The following object is masked from 㤼㸱package:graphics㤼㸲:

    layout
library(purrr)
library(furrr)
Loading required package: future
source("gg_ordisurf_viridis.R")

LOAD OBJECTS IF HAVE RUN ALREADY

geodist_pa<-readRDS(file.path(dataPath,"inputs/BarentsDeep_geodist_pa.rds"))
geodist_r6<-readRDS(file.path(dataPath,"inputs/BarentsDeep_geodist_r6.rds"))

mds_pa<-readRDS(file.path(dataPath,"inputs/BarentsDeep_mds_pa.rds"))
mds_r6<-readRDS(file.path(dataPath,"inputs/BarentsDeep_mds_r6.rds"))
#mds_r6_1000<-readRDS(file.path(dataPath,"inputs/BarentsDeep_mds_r6_1000rep.rds"))

ep<-0.8 #epsilon (to avoid having to find and run just this line from code blocks where the mds objects were made)

Combine Barents and Deep datasets

env_sort1 <- read.csv(file.path(dataPath,"inputs/SPLITS/BARENTS/LDnoSBhi02_env_sort_2022-09-29.csv")) %>% as.data.frame
otu_sort1 <- read.csv(file.path(dataPath,"inputs/SPLITS/BARENTS/LDnoSBhi02_otu_sort_2022-09-29.csv")) %>% as.data.frame

env_sort2 <- read.csv(file.path(dataPath,"inputs/SPLITS/DEEP/HDensDeep_env_sort_2022-09-29.csv")) %>% as.data.frame
otu_sort2 <- read.csv(file.path(dataPath,"inputs/SPLITS/DEEP/HDensDeep_otu_sort_2022-09-29.csv")) %>% as.data.frame

env_orig <- rbind(env_sort1,env_sort2)
otu_orig <- rbind(otu_sort1, otu_sort2)
#joinedDat<-otu_orig%>% dplyr::left_join(.,env_orig, by="SampID")
joinedDat<- left_join(otu_orig,env_orig, by=c("SampID"="SampID"))

otu_sort<-joinedDat %>% select(c(2:391))
env_sort<-joinedDat %>% select(c(2,393:528))

# Sorting and ordering by SampID
# env_orig <- env_orig[order(env_orig$SampID), ]
# otu_orig <- otu_orig[order(otu_orig$SampID), ]

table(env_sort$SampID == otu_sort$SampID)

TRUE 
1883 
#must be same length and equal to unique sample number length - the ordered lists are assumed to be directly relatable on a row by row basis

dim(env_sort)
[1] 1883  137
dim(otu_sort)
[1] 1883  390

Data

table(env_sort$SampID2 == otu_sort$SampID)
< table of extent 0 >
#must be same length and equal to unique sample number length - the ordered lists are assumed to be directly relatable on a row by row basis

dim(env_sort)
[1] 1883  137
dim(otu_sort)
[1] 1883  390

remove any variables with not enough coverage


env_sort <- env_sort %>% select(-c("BO22_lightbotmean_bdmean",
                               "BO22_lightbotltmax_bdmean",
                               "BO22_lightbotltmin_bdmean",
                               "BO22_lightbotrange_bdmean"))

env_sort$X.y<-env_sort$X.y.y

Plot map to check location of samples

env_sort_locations<- ggplot(data = env_sort,
                      aes(x = X.y,
                          y = Y)) +
  theme_classic() +
  geom_point(aes(colour = bathy),
             size = 2) +
  scale_colour_gradient2(low = "red",
                         mid = "yellow",
                         high = "green") +
  ggtitle("Location of samples in sorted env file")

env_sort_locations

Data cleaning

## Removing NAs
otuCompl <- otu_sort[complete.cases(env_sort[, -c(1:which(colnames(env_sort)=="bathy")-1)]), ]
envCompl <- env_sort[complete.cases(env_sort[, -c(1:which(colnames(env_sort)=="bathy")-1)]), ]

## Removing observations with less than 4 OTUs
sel <- rowSums(otuCompl[, -c(1)]) >= 4
otuSel <- otuCompl[sel, ]
envSel <- envCompl[sel, ]


## Removing phosphate
#envSel <- envSel %>% select(-phosphate_mean.tif)


dim(otuSel); dim(envSel)
[1] 1676  390
[1] 1676  134

Show what samples are left after complete cases and >4 OTUs filters

env_sel_locations<- ggplot(data = envSel,
                      aes(x = X.y,
                          y = Y)) +
  theme_classic() +
  geom_point(aes(colour = bathy),
             size = 2) +
  scale_colour_gradient2(low = "red",
                         mid = "yellow",
                         high = "green") +
  ggtitle("Location of samples in sorted env file")

env_sel_locations

Show what got removed in complete cases filter

envCompl_ccrem<-env_sort%>%filter(!SampID%in%envCompl$SampID)

envCompl_ccrem_locations<- ggplot(data = envCompl_ccrem,
                      aes(x = X.y,
                          y = Y)) +
  theme_classic() +
  geom_point(aes(colour = bathy),
             size = 2) +
  scale_colour_gradient2(low = "red",
                         mid = "yellow",
                         high = "green") +
  ggtitle("Location of removed complete case samples resulting in envSel file")

envCompl_ccrem_locations

Show what got removed in <4 OTUs filter

inv.sel <- rowSums(otuCompl[, -c(1:2)]) < 4
env.invSel <- envCompl[inv.sel, ]

env.invSel_locations<- ggplot(data = env.invSel,
                      aes(x = X.y,
                          y = Y)) +
  theme_classic() +
  geom_point(aes(colour = bathy),
             size = 2) +
  scale_colour_gradient2(low = "red",
                         mid = "yellow",
                         high = "green") +
  ggtitle("Location of removed samples with <4 OTUs resulting in envSel file")

env.invSel_locations

[Optional] Data thinning

# otu_red <- otu1[1:500, ]
# otu <- otu_red
# 
# env_red <- env[1:500, ]
# env <- env_red

Whole dataset for first run

otu<-otuSel[,-c(1:which(colnames(otuSel)=="Acesta_excavata")-1)]
env<-envSel[, -c(2:(which(colnames(envSel)=="bathy")-1))]

table(is.na(otu))

 FALSE 
651964 
table(is.na(env))

 FALSE 
197768 
#str(otuSel)
#str(envSel)

Splitting in subsets

# ## Class 1
# otu1 <- subset(otuSel, envSel$SplitRev == 1)
# env1 <- envSel %>% filter(SplitRev == 1)
# 
# ## Class 2
# otu2 <- subset(otuSel, envSel$SplitRev == 2)
# env2 <- envSel %>% filter(SplitRev == 2)
# 
# ## Class 4
# otu3 <- subset(otuSel, envSel$SplitRev == 3)
# env3 <- envSel %>% filter(SplitRev == 3)
# 
# ## Class 4
# otu4 <- subset(otuSel, envSel$SplitRev == 4)
# env4 <- envSel %>% filter(SplitRev == 4)
# 
# ## Class 6
# otu6 <- subset(otuSel, envSel$SplitRev == 6)
# env6 <- envSel %>% filter(SplitRev == 6)
# 
# ## Class 7
# otu7 <- subset(otuSel, envSel$SplitRev == 7)
# env7 <- envSel %>% filter(SplitRev == 7)
# 
# ## Class 8
# otu8 <- subset(otuSel, envSel$SplitRev == 8)
# env8 <- envSel %>% filter(SplitRev == 8)

Selecting subset

# ## Selecting 
# otu <- otu2
# env <- env2

format data correctly

#env$coords.x1<-as.numeric(env$coords.x1)
#env$coords.x2<-as.numeric(env$coords.x2)

Abundance weighting

Make function You might have to drop variables that have been imported as character


otu_pa <- decostand(x = otu[, -c(1)],
                    method = "pa")

# y = ax^w         # power transformation formula
dt <- otu[, -c(1:2)]          # species data to transform
x_mn <- min(dt[dt > 0])
x_mx <- max(dt)
rng <- 6           # abundance range
w <- log(rng) / (log(x_mx) - log(x_mn))
a <- x_mn^(-w)
# otu_6 <- a * dt[, -c(1:3)]^w
otu_6 <- a * dt^w
range(otu_6)
[1] 0 6

Ordination methods

DCA PA

Sys.time()
[1] "2022-09-29 23:46:54 CEST"
dca_pa <- decorana(veg = otu_pa)
some species were removed because they were missing in the data
print(dca_pa, head=T)

Call:
decorana(veg = otu_pa) 

Detrended correspondence analysis with 26 segments.
Rescaling of axes with 4 iterations.

                  DCA1   DCA2   DCA3   DCA4
Eigenvalues     0.5113 0.3652 0.2255 0.2934
Decorana values 0.5496 0.3584 0.3320 0.2648
Axis lengths    5.6856 3.9595 2.4912 2.7604

GNMDS PA

Distances - don’t run if loading saved object

## Bray-Curtis
dist_pa <- vegdist(x = otu_pa, method = "bray")

## Geodist
ep <- 0.8     # epsilon
geodist_pa <- isomapdist(dist = dist_pa, epsilon = ep)
Save the result - don’t run if loading saved object
saveRDS(geodist_pa,
        file = (file.path(dataPath,"inputs/BarentsDeep_geodist_pa.rds")))

Ordination

monoMDS - don’t run if loading saved object

took 6.4mins with jonatan’s paralell solution (usually ~10mins)

# 
# Sys.time()
# d <- 2
# mds_pa <- list()
# 
# for (i in 1:100) {
#   mds_pa[[i]]<-monoMDS(geodist_pa,
#                     matrix(c(runif(dim(otu_pa)[1]*d)),
#                            nrow = dim(otu_pa)[1]),
#                     k = d,
#                     model = "global",
#                     maxit = 2000,
#                     smin = 1e-7,
#                     sfgrmin = 1e-7)
# }
# Sys.time()


## monoMDS
# d <- 2
# mds_r6 <- list()
# 
# Sys.time()
# for (i in 1:200) {
#   mds_r6[[i]]<-monoMDS(geodist_r6,
#                     matrix(c(runif(dim(otu_6)[1]*d)),
#                            nrow = dim(otu_6)[1]),
#                     k = d,
#                     model = "global",
#                     maxit = 2000,
#                     smin = 1e-7,
#                     sfgrmin = 1e-7)
# }
# Sys.time()

#Jonatan's upgrade for speed - parallel processing of mds reptitions
library(furrr) # Package to run non sequential functions in parallel
#library(purrr)
plan(multisession)

d <- 2

i <-200 # number of reps

List_geodist_pa <- lapply(seq_len(i), function(X) geodist_pa) # makes a list with the input data repeated as many times as reps wanted
start_t<-Sys.time()
mds_pa<-furrr::future_map(List_geodist_pa, 
                  function(x) monoMDS(x,
                                      matrix(c(runif(dim(otu_6)[1]*d)),
                                             nrow = dim(otu_6)[1]),
                                      k = d,
                                      model = "global",
                                      maxit = 2000,
                                      smin = 1e-7,
                                      sfgrmin = 1e-7),
                  .progress = TRUE)

 Progress: ---                                                              100%
 Progress: ---                                                              100%
 Progress: ---                                                              100%
 Progress: ---                                                              100%
 Progress: ---                                                              100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: ------                                                           100%
 Progress: ------                                                           100%
 Progress: ------                                                           100%
 Progress: ------                                                           100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: ---------                                                        100%
 Progress: ---------                                                        100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: ---------------                                                  100%
 Progress: ---------------                                                  100%
 Progress: ---------------                                                  100%
 Progress: ---------------                                                  100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: ------------------                                               100%
 Progress: ------------------                                               100%
 Progress: ------------------                                               100%
 Progress: ------------------                                               100%
 Progress: ------------------                                               100%
 Progress: ------------------                                               100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: --------------------                                             100%
 Progress: --------------------                                             100%
 Progress: --------------------                                             100%
 Progress: --------------------                                             100%
 Progress: --------------------                                             100%
 Progress: --------------------                                             100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: -----------------------                                          100%
 Progress: -----------------------                                          100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: --------------------------                                       100%
 Progress: --------------------------                                       100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: -----------------------------                                    100%
 Progress: -----------------------------                                    100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: -----------------------------------                              100%
 Progress: -----------------------------------                              100%
 Progress: -----------------------------------                              100%
 Progress: -----------------------------------                              100%
 Progress: -----------------------------------                              100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: ---------------------------------------                          100%
 Progress: ---------------------------------------                          100%
 Progress: ---------------------------------------                          100%
 Progress: ---------------------------------------                          100%
 Progress: ---------------------------------------                          100%
 Progress: ----------------------------------------                         100%
 Progress: ----------------------------------------                         100%
 Progress: ----------------------------------------                         100%
 Progress: ----------------------------------------                         100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: -------------------------------------------                      100%
 Progress: -------------------------------------------                      100%
 Progress: -------------------------------------------                      100%
 Progress: -------------------------------------------                      100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ----------------------------------------------                   100%
 Progress: ----------------------------------------------                   100%
 Progress: ----------------------------------------------                   100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: -------------------------------------------------                100%
 Progress: -------------------------------------------------                100%
 Progress: -------------------------------------------------                100%
 Progress: -------------------------------------------------                100%
 Progress: -------------------------------------------------                100%
 Progress: -------------------------------------------------                100%
 Progress: --------------------------------------------------               100%
 Progress: --------------------------------------------------               100%
 Progress: --------------------------------------------------               100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ----------------------------------------------------             100%
 Progress: ----------------------------------------------------             100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: -------------------------------------------------------          100%
 Progress: -------------------------------------------------------          100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: ---------------------------------------------------------        100%
 Progress: ----------------------------------------------------------       100%
 Progress: ----------------------------------------------------------       100%
 Progress: ----------------------------------------------------------       100%
 Progress: ----------------------------------------------------------       100%
 Progress: ----------------------------------------------------------       100%
 Progress: ------------------------------------------------------------     100%
 Progress: ------------------------------------------------------------     100%
 Progress: ------------------------------------------------------------     100%
 Progress: -------------------------------------------------------------    100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".
Sys.time() - start_t
Time difference of 19.40465 mins
Save the result - don’t run if loading saved object

can take a few mins

saveRDS(mds_pa,
        file = file.path(dataPath,"inputs/BarentsDeep_mds_pa.rds"))
Best nmds solution - PA

Make function?

# Loading geodist object
# geodist_nfi <- readRDS(file = "../SplitRev2_geodist_pa_full.rds")
# Loading mds results
# mds <- readRDS(file = "../SplitRev2_mds_pa_full.rds")

## Extracting the stress of each nmds iteration
mds_stress_pa<-unlist(lapply(mds_pa, function(v){v[[22]]})) 

ordered_pa <-order(mds_stress_pa)

## Best, second best, and worst solution
mds_stress_pa[ordered_pa[1]]
[1] 0.2718277
mds_stress_pa[ordered_pa[2]]
[1] 0.2731914
mds_stress_pa[ordered_pa[10]]
[1] 0.2739577
## Scaling of axes to half change units and varimax rotation by postMDS
mds_best_pa<-postMDS(mds_pa[[ordered_pa[1]]],
                  geodist_pa, 
                  pc = TRUE, 
                  halfchange = TRUE, 
                  threshold = ep)     # Is this threshold related to the epsilon above?
mds_best_pa

Call:
monoMDS(dist = x, y = matrix(c(runif(dim(otu_6)[1] * d)), nrow = dim(otu_6)[1]),      k = d, model = "global", maxit = 2000, smin = 1e-07, sfgrmin = 1e-07) 

Non-metric Multidimensional Scaling

1676 points, dissimilarity ‘bray shortest isomap’, call ‘isomapdist(dist = dist_pa, epsilon = ep)’

Dimensions: 2 
Stress:     0.2718277 
Stress type 1, weak ties
Scores scaled to unit root mean square, rotated to principal components
Stopped after 106 iterations: Scale factor of gradient nearly zero (< sfgrmin)
mds_secbest_pa <- postMDS(mds_pa[[ordered_pa[2]]],
                          geodist_pa, 
                          pc = TRUE, 
                          halfchange = TRUE, 
                          threshold = ep)
mds_secbest_pa

Call:
monoMDS(dist = x, y = matrix(c(runif(dim(otu_6)[1] * d)), nrow = dim(otu_6)[1]),      k = d, model = "global", maxit = 2000, smin = 1e-07, sfgrmin = 1e-07) 

Non-metric Multidimensional Scaling

1676 points, dissimilarity ‘bray shortest isomap’, call ‘isomapdist(dist = dist_pa, epsilon = ep)’

Dimensions: 2 
Stress:     0.2731914 
Stress type 1, weak ties
Scores scaled to unit root mean square, rotated to principal components
Stopped after 198 iterations: Scale factor of gradient nearly zero (< sfgrmin)
## Procrustes comparisons
procr_pa <- procrustes(mds_best_pa,
                    mds_secbest_pa,
                    permutations=999)
protest(mds_best_pa,
        mds_secbest_pa,
        permutations=999)

Call:
protest(X = mds_best_pa, Y = mds_secbest_pa, permutations = 999) 

Procrustes Sum of Squares (m12 squared):        0.105 
Correlation in a symmetric Procrustes rotation: 0.9461 
Significance:  0.001 

Permutation: free
Number of permutations: 999
plot(procr_pa)

png(file=file.path(dataPath,"outputs/BarentsDeep_procrustes_pa.png"), width=1000, height=700)
plot(procr_pa)
dev.off()
png 
  2 

Correlation of axis: DCA vs NMDS - PA
# Extracting ordination axis
ax <- 2
axis_pa <- cbind(mds_best_pa$points,
                 scores(dca_pa,
                        display = "sites",
                        origin = TRUE)[, 1:ax])

ggcorr(axis_pa, 
       method=c("everything","kendall"), 
       label = TRUE,
       label_size = 3, 
       label_color = "black",  
       nbreaks = 8,
       label_round = 3,
       low = "red",
       mid = "white",
       high = "green")

NA
NA
Save the figure
ggsave(filename = file.path(dataPath,"outputs/BarentsDeep_correlationPCAvsNMDS_PA.png"),
       device = "png",
       dpi=300 )
Saving 7 x 7 in image
# Switching direction of NMDS1
# mds_best$points[, 1] <- -mds_best$points[, 1]

DCA R6

dca_r6 <- decorana(veg = otu_6)
some species were removed because they were missing in the data
print(dca_r6, head=T)

Call:
decorana(veg = otu_6) 

Detrended correspondence analysis with 26 segments.
Rescaling of axes with 4 iterations.

                  DCA1   DCA2   DCA3   DCA4
Eigenvalues     0.5303 0.2641 0.3859 0.3160
Decorana values 0.5702 0.3993 0.3733 0.3032
Axis lengths    5.3863 1.5392 4.3342 5.7681

GNMDS R6

Distances - don’t run if loading saved object

## Bray-Curtis
dist_r6 <- vegdist(x = otu_6, method = "bray")

## Geodist
ep <- 0.80     # epsilon
geodist_r6 <- isomapdist(dist = dist_r6, epsilon = ep)
Save the result - don’t run if loading saved object
saveRDS(geodist_r6,
        file = (file.path(dataPath,"inputs/BarentsDeep_geodist_r6.rds")))

Ordination

200 reps - don’t run if loading saved object

Jonatan’s parallel solution took 5.4mins, before it took 10mins

## monoMDS
# d <- 2
# mds_r6 <- list()
# 
# Sys.time()
# for (i in 1:200) {
#   mds_r6[[i]]<-monoMDS(geodist_r6,
#                     matrix(c(runif(dim(otu_6)[1]*d)),
#                            nrow = dim(otu_6)[1]),
#                     k = d,
#                     model = "global",
#                     maxit = 2000,
#                     smin = 1e-7,
#                     sfgrmin = 1e-7)
# }
# Sys.time()

#Jonatan's upgrade for speed - parallel processing of mds reptitions
#library(furrr) # Package to run non sequential functions in parallel
#library(purrr)
plan(multisession)

d <- 2

i <-200 # number of reps

List_geodist_r6 <- lapply(seq_len(i), function(X) geodist_r6) # makes a list with the input data repeated as many times as reps wanted
start_t<-Sys.time()
mds_r6<-furrr::future_map(List_geodist_r6, 
                  function(x) monoMDS(x,
                                      matrix(c(runif(dim(otu_6)[1]*d)),
                                             nrow = dim(otu_6)[1]),
                                      k = d,
                                      model = "global",
                                      maxit = 2000,
                                      smin = 1e-7,
                                      sfgrmin = 1e-7),
                  .progress = TRUE)

 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: ----                                                             100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: -----                                                            100%
 Progress: ------                                                           100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: -------                                                          100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: --------                                                         100%
 Progress: ---------                                                        100%
 Progress: ---------                                                        100%
 Progress: ---------                                                        100%
 Progress: ---------                                                        100%
 Progress: ---------                                                        100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: ----------                                                       100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: -----------                                                      100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: ------------                                                     100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: -------------                                                    100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: --------------                                                   100%
 Progress: ---------------                                                  100%
 Progress: ---------------                                                  100%
 Progress: ---------------                                                  100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: ----------------                                                 100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: -----------------                                                100%
 Progress: ------------------                                               100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: -------------------                                              100%
 Progress: --------------------                                             100%
 Progress: --------------------                                             100%
 Progress: --------------------                                             100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ---------------------                                            100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: ----------------------                                           100%
 Progress: -----------------------                                          100%
 Progress: -----------------------                                          100%
 Progress: -----------------------                                          100%
 Progress: -----------------------                                          100%
 Progress: -----------------------                                          100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: ------------------------                                         100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: -------------------------                                        100%
 Progress: --------------------------                                       100%
 Progress: --------------------------                                       100%
 Progress: --------------------------                                       100%
 Progress: --------------------------                                       100%
 Progress: --------------------------                                       100%
 Progress: --------------------------                                       100%
 Progress: --------------------------                                       100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ---------------------------                                      100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: ----------------------------                                     100%
 Progress: -----------------------------                                    100%
 Progress: -----------------------------                                    100%
 Progress: -----------------------------                                    100%
 Progress: -----------------------------                                    100%
 Progress: -----------------------------                                    100%
 Progress: -----------------------------                                    100%
 Progress: -----------------------------                                    100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: ------------------------------                                   100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: -------------------------------                                  100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: --------------------------------                                 100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ---------------------------------                                100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: ----------------------------------                               100%
 Progress: -----------------------------------                              100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: ------------------------------------                             100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: -------------------------------------                            100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: --------------------------------------                           100%
 Progress: ---------------------------------------                          100%
 Progress: ---------------------------------------                          100%
 Progress: ---------------------------------------                          100%
 Progress: ----------------------------------------                         100%
 Progress: ----------------------------------------                         100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: -----------------------------------------                        100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: ------------------------------------------                       100%
 Progress: -------------------------------------------                      100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: --------------------------------------------                     100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ---------------------------------------------                    100%
 Progress: ----------------------------------------------                   100%
 Progress: ----------------------------------------------                   100%
 Progress: ----------------------------------------------                   100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: -----------------------------------------------                  100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: ------------------------------------------------                 100%
 Progress: -------------------------------------------------                100%
 Progress: -------------------------------------------------                100%
 Progress: -------------------------------------------------                100%
 Progress: --------------------------------------------------               100%
 Progress: --------------------------------------------------               100%
 Progress: --------------------------------------------------               100%
 Progress: --------------------------------------------------               100%
 Progress: --------------------------------------------------               100%
 Progress: --------------------------------------------------               100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ---------------------------------------------------              100%
 Progress: ----------------------------------------------------             100%
 Progress: ----------------------------------------------------             100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: -----------------------------------------------------            100%
 Progress: ------------------------------------------------------           100%
 Progress: ------------------------------------------------------           100%
 Progress: -------------------------------------------------------          100%
 Progress: -------------------------------------------------------          100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: --------------------------------------------------------         100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ---------------------------------------------------------        100%
 Progress: ----------------------------------------------------------       100%
 Progress: ----------------------------------------------------------       100%
 Progress: -----------------------------------------------------------      100%
 Progress: -------------------------------------------------------------    100%
 Progress: -------------------------------------------------------------    100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: --------------------------------------------------------------   100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------  100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%
 Progress: ---------------------------------------------------------------- 100%UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".UNRELIABLE VALUE: Future (㤼㸱<none>㤼㸲) unexpectedly generated random numbers without specifying argument 'seed'. There is a risk that those random numbers are not statistically sound and the overall results might be invalid. To fix this, specify 'seed=TRUE'. This ensures that proper, parallel-safe random numbers are produced via the L'Ecuyer-CMRG method. To disable this check, use 'seed=NULL', or set option 'future.rng.onMisuse' to "ignore".
Sys.time() - start_t
Time difference of 15.123 mins
Save the result - don’t run if loading saved object
saveRDS(mds_r6,
        file = file.path(dataPath,"inputs/BarentsDeep_mds_r6.rds")) 
Best nmds solution r6 200 rep
# Loading geodist object
# geodist_nfi <- readRDS(file = "../SplitRev2_geodist_nfi.rds")

# Loading mds results
# mds <- readRDS(file = "../SplitRev2_mds.rds")

## Extracting the stress of each nmds iteration
mds_stress_r6<-unlist(lapply(mds_r6, function(v){v[[22]]})) 

ordered_r6 <-order(mds_stress_r6)

## Best, second best, and worst solution
mds_stress_r6[ordered_r6[1]]
[1] 0.2669464
mds_stress_r6[ordered_r6[2]]
[1] 0.2678038
mds_stress_r6[ordered_r6[100]]
[1] 0.2742299
## Scaling of axes to half change units and varimax rotation by postMDS
mds_best_r6<-postMDS(mds_r6[[ordered_r6[1]]],
                     geodist_r6, 
                     pc = TRUE, 
                     halfchange = TRUE, 
                     threshold = ep)     # Is this threshold related to the epsilon above?
mds_best_r6

Call:
monoMDS(dist = x, y = matrix(c(runif(dim(otu_6)[1] * d)), nrow = dim(otu_6)[1]),      k = d, model = "global", maxit = 2000, smin = 1e-07, sfgrmin = 1e-07) 

Non-metric Multidimensional Scaling

1676 points, dissimilarity ‘bray shortest isomap’, call ‘isomapdist(dist = dist_r6, epsilon = ep)’

Dimensions: 2 
Stress:     0.2669464 
Stress type 1, weak ties
Scores scaled to unit root mean square, rotated to principal components
Stopped after 147 iterations: Scale factor of gradient nearly zero (< sfgrmin)
mds_secbest_r6<-postMDS(mds_r6[[ordered_r6[2]]],
                        geodist_r6, 
                        pc = TRUE, 
                        halfchange = TRUE, 
                        threshold = ep)
mds_secbest_r6

Call:
monoMDS(dist = x, y = matrix(c(runif(dim(otu_6)[1] * d)), nrow = dim(otu_6)[1]),      k = d, model = "global", maxit = 2000, smin = 1e-07, sfgrmin = 1e-07) 

Non-metric Multidimensional Scaling

1676 points, dissimilarity ‘bray shortest isomap’, call ‘isomapdist(dist = dist_r6, epsilon = ep)’

Dimensions: 2 
Stress:     0.2678038 
Stress type 1, weak ties
Scores scaled to unit root mean square, rotated to principal components
Stopped after 111 iterations: Scale factor of gradient nearly zero (< sfgrmin)
## Procrustes comparisons
procr_r6 <- procrustes(mds_best_r6,
                       mds_secbest_r6,
                       permutations=999)
protest(mds_best_r6,
        mds_secbest_r6,
        permutations=999)

Call:
protest(X = mds_best_r6, Y = mds_secbest_r6, permutations = 999) 

Procrustes Sum of Squares (m12 squared):        0.05042 
Correlation in a symmetric Procrustes rotation: 0.9745 
Significance:  0.001 

Permutation: free
Number of permutations: 999
plot(procr_r6)

png(file.path(dataPath,"outputs/BarentsDeep_procrustes_r6.png"), width=1000, height=700,) #added 1000
plot(procr_r6)
dev.off()
png 
  2 

#### 1000 reps - don’t run if loading saved object Currently commented out as it gained nothing but took extra time. Can be removed in due course.

Correlation of axis: DCA vs NMDS

retain the 200 rep version

# Extracting ordination axis
ax <- 2
axis_r6 <- cbind(mds_best_r6$points,
                 scores(dca_r6,
                        display = "sites",
                        origin = TRUE)[, 1:ax])

ggcorr(axis_r6, 
       method=c("everything","kendall"), 
       label = TRUE,
       label_size = 3, 
       label_color = "black",  
       nbreaks = 8,
       label_round = 3,
       low = "red",
       mid = "white",
       high = "green")

Save the figure
ggsave(filename = file.path(dataPath,"outputs/BarentsDeep_correlationPCAvsNMDS_r6.png"),
       device = "png",
       dpi=300 )
Saving 7 x 7 in image
# Switching direction of NMDS1
# mds_best$points[, 1] <- -mds_best$points[, 1]

Plotting DCA & GNMDS

## Adding scores to data frame
otu_6$gnmds1 <- mds_best_r6$points[, 1]
otu_6$gnmds2 <- mds_best_r6$points[, 2]
otu_6$dca1 <- scores(dca_r6, display = "sites", origin = TRUE)[, 1]
otu_6$dca2 <- scores(dca_r6, display = "sites", origin = TRUE)[, 2]

p_gnmds_r6 <- ggplot(data = otu_6,
                     aes(x = gnmds1,
                         y = gnmds2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("GNMDS",
          subtitle = "First run") +
  geom_point(colour = "red") +
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")

p_dca_r6 <- ggplot(data = otu_6,
                   aes(x = -dca1,
                       y = dca2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("DCA",
          subtitle = "First run") +
  geom_point(colour = "red") +
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")

p_gnmds_r6 + p_dca_r6

NA
NA
Save the figure
ggsave(file.path(dataPath,"outputs/BarentsDeep_gnmds_dca_r6.png"),
       device = "png", 
       dpi=300)
Saving 7 x 7 in image

Species-environment relationships

Selecting ordination

ord <- mds_best_r6

## Axis scores if selected ord is GNMDS
axis <- ord$points %>% as.data.frame

## Axis scores if selected ord is DCA
# axis <- scores(ord,
#                display = "sites",
#                origin = TRUE)[, 1:ax])

Create additional variables

decided to make MLD-bathy vars

env<-env %>% 
  mutate ("MLDmean_bathy"=MLDmean_Robinson-(bathy*-1),
          "MLDmin_bathy"=MLDmin_Robinson-(bathy*-1),
          "MLDmax_bathy"=MLDmax_Robinson-(bathy*-1))

env$MLDmean_bathy<-cut(env$MLDmean_bathy, 
      breaks=c(-2560, -20,20,130),#checked range of values first (min -2554, max 123)
      labels=c('belowMLD','onPycno','inMixLayer'))
env$MLDmin_bathy<-cut(env$MLDmin_bathy, 
      breaks=c(-2560, -20,20,130),#checked range of values first (min -2554, max 123)
      labels=c('belowMLD','onPycno','inMixLayer'))
env$MLDmax_bathy<-cut(env$MLDmax_bathy, 
      breaks=c(-2560, -20,20,130),#checked range of values first (min -2554, max 123)
      labels=c('belowMLD','onPycno','inMixLayer'))

env$swDensRob_avs<-swRho(salinity=env$Smean_Robinson,
                         temperature=env$Tmean_Robinson,
                         pressure=(env$bathy*-1),
                         eos="unesco")

Correlation ordination axes and environmental variables

Removing non-env vars

env_cont<-env%>% select(-c(landscape,sedclass,gmorph, MLDmean_bathy, MLDmax_bathy, MLDmin_bathy, #categorical
                           optional, #not a var
                           MLDmax_Robinson, MLDmean_Robinson, MLDmin_Robinson,  #replaced by new vars
                           MLDsd_Robinson, #not meaningful
                           SampID))
env_cont<-env_cont%>% mutate_if(is.integer,as.numeric)
env_corr <- env_cont #%>% select(-c(SampID))

# env_corr$coords.x1<-as.numeric(env_corr$coords.x1)
# env_corr$coords.x2<-as.numeric(env_corr$coords.x2)

env_corr[(!is.numeric(env_corr)),]

Correlations

# Vector to hold correlations
cor_ax1 <- NULL
cor_ax2 <- NULL
pv_ax1 <- NULL
pv_ax2 <- NULL

# NMDS1
for( i in seq(length(env_corr))) {
  ct.i <- cor.test(axis$MDS1,
                   env_corr[, i],
                   method = "kendall")
  cor_ax1[i] <- ct.i$estimate
  pv_ax1[i] <- ct.i$p.value
}

# NMDS2
for( i in seq(length(env_corr))) {
  ct.i <- cor.test(axis$MDS2,
                   env_corr[, i],
                   method = "kendall")
  cor_ax2[i] <- ct.i$estimate
  pv_ax2[i] <- ct.i$p.value
}

cor_tab <- data.frame(env = names(env_corr),
                      ord_ax1 = cor_ax1,
                      pval_ax1 = pv_ax1,
                      ord_ax2 = cor_ax2,
                      pval_ax2 = pv_ax2)

cor_tab

write.csv(x = cor_tab,
          file = file.path(dataPath,"inputs/BarentsDeep_cor-table_r6_200rep_MLD-bathy.csv"),
          row.names = FALSE)

Dot chart to check for gaps in correlation

cor_a1_sort<-cor_tab%>%
  mutate(abs_ord_ax1=abs(ord_ax1),
         abs_ord_ax2=abs(ord_ax2)) %>%
  arrange(desc(abs_ord_ax1))

cor_a2_sort<-cor_tab%>%
  mutate(abs_ord_ax1=abs(ord_ax1),
         abs_ord_ax2=abs(ord_ax2)) %>%
  arrange(desc(abs_ord_ax2))

dotchart(cor_a1_sort$abs_ord_ax1, main="Absolute (+/-) correlations between envVars and gnmds axis 1")


cor_cut<-0.49 #decide

cor_sel<-subset(cor_a1_sort,abs_ord_ax1>cor_cut)
cor_sel

as.data.frame(cor_sel$env)

Sel env var (top corr)

env_os <- env[, cor_sel$env]
env_os
str(env_os)
'data.frame':   1676 obs. of  26 variables:
 $ swDensRob_avs               : num  1029 1029 1029 1029 1029 ...
 $ bathy                       : num  -295 -292 -292 -270 -270 ...
 $ BO22_silicatemean_bdmean    : num  5.71 5.71 5.71 5.7 5.7 ...
 $ BO22_silicaterange_bdmean   : num  5.71 5.71 5.71 5.7 5.7 ...
 $ BO22_silicateltmin_bdmean   : num  4.83 4.83 4.83 4.82 4.81 ...
 $ BO22_chloltmax_bdmean       : num  0.196 0.198 0.198 0.21 0.21 ...
 $ BO22_carbonphytoltmax_bdmean: num  0.581 0.585 0.584 0.621 0.62 ...
 $ BO22_phosphateltmax_bdmean  : num  0.694 0.694 0.694 0.696 0.696 ...
 $ BO22_chlomean_bdmean        : num  0.0805 0.0809 0.0808 0.0846 0.0845 ...
 $ BO22_chlorange_bdmean       : num  0.0805 0.0809 0.0808 0.0846 0.0845 ...
 $ BO22_carbonphytomean_bdmean : num  0.233 0.235 0.234 0.245 0.245 ...
 $ BO22_carbonphytorange_bdmean: num  0.233 0.235 0.234 0.245 0.245 ...
 $ BO22_phosphatemean_bdmean   : num  0.65 0.65 0.65 0.649 0.649 ...
 $ BO22_phosphaterange_bdmean  : num  0.65 0.65 0.65 0.649 0.649 ...
 $ BO22_silicateltmax_bdmean   : num  6.55 6.55 6.55 6.58 6.58 ...
 $ BO22_phosphateltmin_bdmean  : num  0.594 0.593 0.593 0.593 0.592 ...
 $ BO22_ppltmin_ss             : num  0 0 0 0 0 0 0 0 0 0 ...
 $ BO22_nitrateltmin_bdmean    : num  7.65 7.64 7.64 7.63 7.63 ...
 $ BO22_nitratemean_bdmean     : num  8.16 8.15 8.15 8.12 8.12 ...
 $ BO22_nitraterange_bdmean    : num  8.16 8.15 8.15 8.12 8.12 ...
 $ BO22_chloltmin_bdmean       : num  0.0315 0.0316 0.0316 0.0325 0.0325 ...
 $ BO22_nitrateltmax_bdmean    : num  8.7 8.69 8.69 8.65 8.65 ...
 $ BO22_ppltmax_bdmean         : num  2.16e-05 2.24e-05 2.24e-05 3.05e-05 3.05e-05 ...
 $ BO22_ppmean_bdmean          : num  2.12e-06 2.23e-06 2.21e-06 3.00e-06 3.00e-06 ...
 $ BO22_pprange_bdmean         : num  2.12e-06 2.23e-06 2.21e-06 3.00e-06 3.00e-06 ...
 $ BO22_carbonphytoltmin_bdmean: num  0.0869 0.0872 0.0871 0.0895 0.0895 ...

Ordisurfs top corr

ordsrfs <- list(length = ncol(env_os))

for (i in seq(ncol(env_os))) {
  os.i <- gg_ordisurf(ord = ord,
                      env.var = env_os[, i],
                      pt.size = 1,
                      # binwidth = 0.05,
                      var.label = names(env_os)[i],
                      gen.text.size = 10,
                      title.text.size = 15,
                      leg.text.size = 10)
  
  ordsrfs[[i]] <- os.i$plot
}


ordsrfs_plt <- ggarrange(plotlist = ordsrfs,
                         nrow = 5,
                         ncol = 6)

ordsrfs_plt

Save some outputs
ggexport(ordsrfs_plt,
          filename = file.path(dataPath,"outputs/BarentsDeep_ordisurfs_top_corr.png"),
          width = 2500,
          height = 2000)

Sel env var (manual)

env_os_m <- env[,c("Tmean_Robinson", #top corr
                  "salt_max", #top corr
                  "Smax_Robinson", #comparison to top corr
                  "swDensRob_avs", #top corr
                  "BO22_icecoverltmax_ss",#top corr ax2
                  "BO22_icecovermean_ss",#top corr
                  "BO22_dissoxmean_bdmean",#top corr
                  #"BO22_carbonphytoltmin_bdmean",#top corr - no clear gradient in ordisurf
                  "BO22_ppltmin_ss", #top corr
                  "X.y", #comparison to Y
                  "Y", #top corr
                  "spd_std", #top corr ax2 (blended model)
                  "CSpdsd_Robinson", #comparison to top corr ax2 (blended model)
                  "mud", #highest sed var ax1 + corr
                  "gravel",#highest sed var ax1 - corr
                  "BO22_silicateltmax_bdmean", #just under top corr ax1
                  "bathy" #intuitive for comparisons
                )]
env_os_m
str(env_os_m)
'data.frame':   1676 obs. of  16 variables:
 $ Tmean_Robinson           : num  4.07 4.07 4.06 3.9 3.9 ...
 $ salt_max                 : num  35 35 35 35 35 ...
 $ Smax_Robinson            : num  35.1 35.1 35.1 35.1 35.1 ...
 $ swDensRob_avs            : num  1029 1029 1029 1029 1029 ...
 $ BO22_icecoverltmax_ss    : num  3.86e-06 3.89e-06 3.96e-06 7.71e-06 7.49e-06 ...
 $ BO22_icecovermean_ss     : num  5.82e-07 5.55e-07 5.82e-07 1.06e-06 1.01e-06 ...
 $ BO22_dissoxmean_bdmean   : num  310 310 310 311 311 ...
 $ BO22_ppltmin_ss          : num  0 0 0 0 0 0 0 0 0 0 ...
 $ X.y                      : num  1075461 1075261 1075261 1073461 1073261 ...
 $ Y                        : num  8125134 8125334 8125534 8137734 8137534 ...
 $ spd_std                  : num  0.054 0.0541 0.0543 0.0516 0.0516 ...
 $ CSpdsd_Robinson          : num  0.0222 0.0223 0.0224 0.0163 0.0165 ...
 $ mud                      : num  69.5 60 60 69.5 69.5 69.5 60 60 60 69.5 ...
 $ gravel                   : num  0.5 15 15 0.5 0.5 0.5 15 15 15 0.5 ...
 $ BO22_silicateltmax_bdmean: num  6.55 6.55 6.55 6.58 6.58 ...
 $ bathy                    : num  -295 -292 -292 -270 -270 ...

Ordisurfs manually selected

ordsrfs_m <- list(length = ncol(env_os_m))

for (i in seq(ncol(env_os_m))) {
  os.i_m <- gg_ordisurf(ord = ord,
                      env.var = env_os_m[, i],
                      pt.size = 1,
                      # binwidth = 0.05,
                      var.label = names(env_os_m)[i],
                      gen.text.size = 10,
                      title.text.size = 15,
                      leg.text.size = 10)
  
  ordsrfs_m[[i]] <- os.i_m$plot
}


ordsrfs_plt_m <- ggarrange(plotlist = ordsrfs_m,
                         nrow = 4,
                         ncol = 4)

ordsrfs_plt_m

Save some outputs
ggexport(ordsrfs_plt_m,
          filename = file.path(dataPath,"outputs/BarentsDeep_ordisurfs_man_sel_domean.png"),
          width = 2000,
          height = 2000)

Envfit

## Select if any var should be excluded from envfit (makes less busy to read)
env_os_m_envfit<-env_os_m [,c("Tmean_Robinson", #top corr
                  "salt_max", #top corr
                  "Smax_Robinson", #comparison to top corr
                  "swDensRob_avs", #top corr
                  "BO22_icecoverltmax_ss",#top corr ax2
                  #"BO22_icecovermean_ss",#top corr
                  "BO22_dissoxmean_bdmean",#top corr
                  #"BO22_dissoxltmin_bdmean",#top corr
                  #"BO22_carbonphytoltmin_bdmean",#top corr - no clear gradient in ordisurf
                  "BO22_ppltmin_ss", #top corr
                  "X.y", #comparison to Y
                  "Y", #top corr
                  "spd_std", #top corr ax2 (blended model)
                 # "CSpdsd_Robinson", #comparison to top corr ax2 (blended model)
                  "mud", #highest sed var ax1 + corr
                  "gravel",#highest sed var ax1 - corr
                  "BO22_silicateltmax_bdmean", #just under top corr ax1
                  "bathy" #intuitive for comparisons
                
  
)]

colnames(env_os_m_envfit)<-c("T", #top corr
                  "sMx", #top corr
                  "SmaxR", #comparison to top corr
                  "swDensR", #top corr
                  "icecovmax",#top corr ax2
                  #"icecovav",#top corr
                  "dissoxav",#top corr
                  #"dissoxmin",#top corr
                  #"BO22_carbonphytoltmin_bdmean",#top corr - no clear gradient in ordisurf
                  "ppltmin", #top corr
                  "X", #comparison to Y
                  "Y", #top corr
                  "spd_std", #top corr ax2 (blended model)
                 # "CSsd", #comparison to top corr ax2 (blended model)
                  "mud", #highest sed var ax1 + corr
                  "gravel",#highest sed var ax1 - corr
                  "SiLtmax", #just under top corr ax1
                  "bathy" #intuitive for comparisons
                 )

## Envfot plot
gg_envfit(ord = ord,
          env = env_os_m_envfit,
          pt.size = 1)


## Envfit analysis

ef <- envfit(ord = ord,
             env = env_os_m_envfit,
             # na.rm = TRUE
             )
efDF <- as.data.frame(scores(ef,
                             display = "vectors"))
Save the plot
ggsave(filename = file.path(dataPath,"outputs/BarentsDeep_EnvFit_man_sel_cln_domean.png"),
       device = "png",
       dpi=300 )
Saving 7 x 7 in image

Categorical envVar visualised on the mdsplots

use dataset with categorical var included

env_vis<-env
env_vis$gnmds1 <- otu_6$gnmds1
env_vis$gnmds2 <- otu_6$gnmds2

env_vis$dca1 <- otu_6$dca1
env_vis$dca2 <- otu_6$dca2

gnmds w mld mean - bathy

dca_int <- ggplot(data = env_vis,
                     aes(x = dca1,
                         y = dca2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("Interactive DCA sample ID plot",
          subtitle = "First run") +
  geom_point(aes(colour = factor(SampID))) +
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")

ggplotly(dca_int)

gnmds w mld mean - bathy

p_mld <- ggplot(data = env_vis,
                     aes(x = gnmds1,
                         y = gnmds2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("GNMDS coloured by proximity to mixed layer depth",
          subtitle = "First run") +
  geom_point(aes(colour = MLDmean_bathy)) +
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")

p_mld

gnmds w sedclass

deal with sedclass codes
env_vis<- env_vis %>% 
  mutate(
    sedclassName = case_when(
            sedclass == "1" ~ "SedCoverR",
            sedclass == "5" ~ "Rock",
            sedclass == "20" ~ "Mud",
            sedclass == "21" ~ "MwBlock",
            sedclass == "40" ~ "sMud",
            sedclass == "80" ~ "mSand",
            sedclass == "100" ~ "Sand",
            sedclass == "110" ~ "gMud",
            sedclass == "115" ~ "gsMud",
            sedclass == "120" ~ "gmSand",
            sedclass == "130" ~ "gSand",
            sedclass == "150" ~ "MSG",
            sedclass == "160" ~ "sGravel",
            sedclass == "170" ~ "Gravel",
            sedclass == "175" ~ "GravBlock",
            sedclass == "185" ~ "SGBmix",
            sedclass == "205" ~ "S/MwB",
            sedclass == "206" ~ "S/MwG/B",
            sedclass == "215" ~ "SGBalt",
            sedclass == "300" ~ "HardSed",
            sedclass == "500" ~ "Biogenic"
                        
    )
  )
colour palette to cope with up to 25 categorical colours
c25 <- c(
  "dodgerblue2", "#E31A1C", # red
  "green4",
  "#6A3D9A", # purple
  "#FF7F00", # orange
  "black", "gold1",
  "skyblue2", "#FB9A99", # lt pink
  "palegreen2",
  "#CAB2D6", # lt purple
  "#FDBF6F", # lt orange
  "gray70", "khaki2",
  "maroon", "orchid1", "deeppink1", "blue1", "steelblue4",
  "darkturquoise", "green1", "yellow4", "yellow3",
  "darkorange4", "brown"
)

p_sed <- ggplot(data = env_vis,
                     aes(x = gnmds1,
                         y = gnmds2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("GNMDS coloured by sediment class",
          subtitle = "First run") +
  geom_point(aes(colour = factor(sedclassName))) +
   scale_colour_manual(values=c25)+
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")+
  guides(colour=guide_legend(ncol=2))

p_sed

gnmds w lanscape

deal with sedclass codes
env_vis<- env_vis %>% 
  mutate(
    landscapeName = case_when(
            landscape == "1" ~ "Strandflat",
            landscape == "21" ~ "ContSlope",
            landscape == "22" ~ "Canyon",
            landscape == "31" ~ "Valley",
            landscape == "32" ~ "Fjord",
            landscape == "41" ~ "DeepPlain",
            landscape == "42" ~ "SlopePlain",
            landscape == "43" ~ "ShelfPlain",
            landscape == "431" ~ "shallowValley"
    )
  )

p_land <- ggplot(data = env_vis,
                     aes(x = gnmds1,
                         y = gnmds2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("GNMDS coloured by landscape class",
          subtitle = "First run") +
  geom_point(aes(colour = factor(landscapeName))) +
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")+
  guides(colour=guide_legend(ncol=2))

p_land

Gnmds w gmorph


p_gmo <- ggplot(data = env_vis,
                     aes(x = gnmds1,
                         y = gnmds2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("GNMDS coloured by landscape class",
          subtitle = "First run") +
  geom_point(aes(colour = factor(gmorph))) +
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")+
  guides(colour=guide_legend(ncol=2))

p_gmo

cat_var_plots<-p_mld+p_sed+p_land+p_gmo
Save the plot
ggexport(cat_var_plots,
          filename = file.path(dataPath,"outputs/BarentsDeep_gnmds_catvar.png"),
          width = 1000,
          height = 800)

Sample identification in the mdsplot

p_gmo <- ggplot(data = env_vis,
                     aes(x = gnmds1,
                         y = gnmds2)) +
  theme_classic() +
  coord_fixed() +
  ggtitle("GNMDS coloured by sample",
          subtitle = "First run") +
  geom_point(aes(colour = factor(SampID))) +
  geom_vline(xintercept = 0,
             linetype = 2,
             colour = "lightgray") +
  geom_hline(yintercept = 0,
             linetype = 2,
             colour = "lightgray")+
  guides(colour="none", size="none")

ggplotly(p_gmo)
LS0tDQp0aXRsZTogIk1BUkVBTk8gLSBOaU4gLSBsb0RlbnMgPDEwMzEuOCB3aXRob3V0IFNwaXRzYmVyZ2VuQmFua2VuIG91dGxpZXJzIg0KYXV0aG9yczogVGhpanMgdmFuIFNvbiwgUnVuZSBIYWx2b3JzZW4sIFJlYmVjY2EgUm9zcywgR2Vub3ZldmEgR29uemFsZXMtTWlyZWxpcywgTWFyZ2FyZXQgRG9sYW4NCmRhdGU6ICJMYXN0IFJlbmRlcmVkIG9uIGByIGZvcm1hdChTeXMudGltZSgpLCAnJWQgJUIsICVZJylgIg0Kb3V0cHV0OiANCiAgaHRtbF9ub3RlYm9vazogDQogICAgdG9jOiB5ZXMNCiAgICB0b2NfZGVwdGg6IDINCiAgICB0b2NfZmxvYXQ6IHllcw0KICAgIGZpZ193aWR0aDogNw0KICAgIGZpZ19oZWlnaHQ6IDcNCmFsd2F5c19hbGxvd19odG1sOiB0cnVlIA0KLS0tDQoNCiMjIFBhY2thZ2VzDQpgYGB7cn0NCmxpYnJhcnkoZHBseXIpDQpsaWJyYXJ5KGdnY29ycnBsb3QpDQpsaWJyYXJ5KGdncHVicikNCmxpYn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0KIyMjIyByZW1vdmUgYW55IHZhcmlhYmxlcyB3aXRoIG5vdCBlbm91Z2ggY292ZXJhZ2UNCmBgYHtyfQ0KDQplbnZfc29ydCA8LSBlbnZfc29ydCAlPiUgc2VsZWN0KC1jKCJCTzIyX2xpZ2h0Ym90bWVhbl9iZG1lYW4iLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJCTzIyX2xpZ2h0Ym90bHRtYXhfYmRtZWFuIiwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiQk8yMl9saWdodGJvdGx0bWluX2JkbWVhbiIsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIkJPMjJfbGlnaHRib3RyYW5nZV9iZG1lYW4iKSkNCg0KZW52X3NvcnQkWC55PC1lbnZfc29ydCRYLnkueQ0KYGBgDQoNCg0KIyMjIyBQbG90IG1hcCB0byBjaGVjayBsb2NhdGlvbiBvZiBzYW1wbGVzDQpgYGB7cn0NCmVudl9zb3J0X2xvY2F0aW9uczwtIGdncGxvdChkYXRhID0gZW52X3NvcnQsDQogICAgICAgICAgICAgICAgICAgICAgYWVzKHggPSBYLnksDQogICAgICAgICAgICAgICAgICAgICAgICAgIHkgPSBZKSkgKw0KICB0aGVtZV9jbGFzc2ljKCkgKw0KICBnZW9tX3BvaW50KGFlcyhjb2xvdXIgPSBiYXRoeSksDQogICAgICAgICAgICAgc2l6ZSA9IDIpICsNCiAgc2NhbGVfY29sb3VyX2dyYWRpZW50Mihsb3cgPSAicmVkIiwNCiAgICAgICAgICAgICAgICAgICAgICAgICBtaWQgPSAieWVsbG93IiwNCiAgICAgICAgICAgICAgICAgICAgICAgICBoaWdoID0gImdyZWVuIikgKw0KICBnZ3RpdGxlKCJMb2NhdGlvbiBvZiBzYW1wbGVzIGluIHNvcnRlZCBlbnYgZmlsZSIpDQoNCmVudl9zb3J0X2xvY2F0aW9ucw0KYGBgDQoNCg0KIyMjIERhdGEgY2xlYW5pbmcNCmBgYHtyfQ0KIyMgUm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AgICAgICBucm93ID0gZGltKG90dV9wYSlbMV0pLA0KIyAgICAgICAgICAgICAgICAgICAgIGsgPSBkLA0KIyAgICAgICAgICAgICAgICAgICAgIG1vZGVsID0gImdsb2JhbCIsDQojICAgICAgICAgICAgICAgICAgICAgbWF4aXQgPSAyMDAwLA0KIyAgICAgICAgICAgICAgICAgICAgIHNtaW4gPSAxZS03LA0KIyAgICAgICAgICAgICAgICAgICAgIHNmZ3JtaW4gPSAxZS03KQ0KIyB9DQojIFN5cy50aW1lKCkNCg0KDQojIyBtb25vTURTDQojIGQgPC0gMg0KIyBtZHNfcjYgPC0gbGlzdCgpDQojIA0KIyBTeXMudGltZSgpDQojIGZvciAoaSBpbiAxOjIwMCkgew0KIyAgIG1kc19yNltbaV1dPC1tb25vTURTKGdlb2Rpc3RfcjYsDQojICAgICAgICAgICAgICAgICAgICAgbWF0cml4KGMocnVuaWYoZGltKG90dV82KVsxXSpkKSksDQojICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5yb3cgPSBkaW0ob3R1XzYpWzFdKSwNCiMgICAgICAgICAgICAgICAgICAgICBrID0gZCwNCiMgICAgICAgICAgICAgICAgICAgICBtb2RlbCA9ICJnbG9iYWwiLA0KIyAgICAgICAgICAgICAgICAgICAgIG1heGl0ID0gMjAwMCwNCiMgICAgICAgICAgICAgICAgICAgICBzbWluID0gMWUtNywNCiMgICAgICAgICAgICAgICAgICAgICBzZmdybWluID0gMWUtNykNCiMgfQ0KIyBTeXMudGltZSgpDQoNCiNKb25hdGFuJ3MgdXBncmFkZSBmb3Igc3BlZWQgLSBwYXJhbGxlbCBwcm9jZXNzaW5nIG9mIG1kcyByZXB0aXRpb25zDQpsaWJyYXJ5KGZ1cnJyKSAjIFBhY2thZ2UgdG8gcnVuIG5vbiBzZXF1ZW50aWFsIGZ1bmN0aW9ucyBpbiBwYXJhbGxlbA0KI2xpYnJhcnkocHVycnIpDQpwbGFuKG11bHRpc2Vzc2lvbikNCg0KZCA8LSAyDQoNCmkgPC0yMDAgIyBudW1iZXIgb2YgcmVwcw0KDQpMaXN0X2dlb2Rpc3RfcGEgPC0gbGFwcGx5KHNlcV9sZW4oaSksIGZ1bmN0aW9uKFgpIGdlb2Rpc3RfcGEpICMgbWFrZXMgYSBsaXN0IHdpdGggdGhlIGlucHV0IGRhdGEgcmVwZWF0ZWQgYXMgbWFueSB0aW1lcyBhcyByZXBzIHdhbnRlZA0Kc3RhcnRfdDwtU3lzLnRpbWUoKQ0KbWRzX3BhPC1mdXJycjo6ZnV0dXJlX21hcChMaXN0X2dlb2Rpc3RfcGEsIA0KICAgICAgICAgICAgICAgICAgZnVuY3Rpb24oeCkgbW9ub01EUyh4LA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXRyaXgoYyhydW5pZihkaW0ob3R1XzYpWzFdKmQpKSwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG5yb3cgPSBkaW0ob3R1XzYpWzFdKSwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgayA9IGQsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1vZGVsID0gImdsb2JhbCIsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIG1heGl0ID0gMjAwMCwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgc21pbiA9IDFlLTcsDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIHNmZ3JtaW4gPSAxZS03KSwNCiAgICAgICAgICAgICAgICAgIC5wcm9ncmVzcyA9IFRSVUUpDQpTeXMudGltZSgpIC0gc3RhcnRfdA0KDQoNCg0KYGBgDQoNCiMjIyMjIFNhdmUgdGhlIHJlc3VsdCAtIGRvbid0IHJ1biBpZiBsb2FkaW5nIHNhdmVkIG9iamVjdA0KY2FuIHRha2UgYSBmZXcgbWlucw0KYGBge3J9DQpzYXZlUkRTKG1kc19wYSwNCiAgICAg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MjAwMCwNCiMgICAgICAgICAgICAgICAgICAgICBzbWluID0gMWUtNywNCiMgICAgICAgICAgICAgICAgICAgICBzZmdybWluID0gMWUtNykNCiMgfQ0KIyBTeXMudGltZSgpDQoNCiNKb25hdGFuJ3MgdXBncmFkZSBmb3Igc3BlZWQgLSBwYXJhbGxlbCBwcm9jZXNzaW5nIG9mIG1kcyByZXB0aXRpb25zDQojbGlicmFyeShmdXJycikgIyBQYWNrYWdlIHRvIHJ1biBub24gc2VxdWVudGlhbCBmdW5jdGlvbnMgaW4gcGFyYWxsZWwNCiNsaWJyYXJ5KHB1cnJyKQ0KcGxhbihtdWx0aXNlc3Npb24pDQoNCmQgPC0gMg0KDQppIDwtMjAwICMgbnVtYmVyIG9mIHJlcHMNCg0KTGlzdF9nZW9kaXN0X3I2IDwtIGxhcHBseShzZXFfbGVuKGkpLCBmdW5jdGlvbihYKSBnZW9kaXN0X3I2KSAjIG1ha2VzIGEgbGlzdCB3aXRoIHRoZSBpbnB1dCBkYXRhIHJlcGVhdGVkIGFzIG1hbnkgdGltZXMgYXMgcmVwcyB3YW50ZWQNCnN0YXJ0X3Q8LVN5cy50aW1lKCkNCm1kc19yNjwtZnVycnI6OmZ1dHVyZV9tYXAoTGlzdF9nZW9kaXN0X3I2LCANCiAgICAgICAgICAgICAgICAgIGZ1bmN0aW9uKHgpIG1vbm9NRFMoeCwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgbWF0cml4KGMocnVuaWYoZGltKG90dV82KVsxXSpkKSksDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBucm93ID0gZGltKG90dV82KVsxXSksDQogICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGsgPSBkLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtb2RlbCA9ICJnbG9iYWwiLA0KICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtYXhpdCA9IDIwMDA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3N1cmU9KGVudiRiYXRoeSotMSksDQogICAgICAgICAgICAgICAgICAgICAgICAgZW9zPSJ1bmVzY28iKQ0KDQpgYGANCg0KDQoNCiMjIyBDb3JyZWxhdGlvbiBvcmRpbmF0aW9uIGF4ZXMgYW5kIGVudmlyb25tZW50YWwgdmFyaWFibGVzDQojIyMjIFJlbW92aW5nIG5vbi1lbnYgdmFycw0KYGBge3J9DQplbnZfY29udDwtZW52JT4lIHNlbGVjdCgtYyhsYW5kc2NhcGUsc2VkY2xhc3MsZ21vcnBoLCBNTERtZWFuX2JhdGh5LCBNTERtYXhfYmF0aHksIE1MRG1pbl9iYXRoeSwgI2NhdGVnb3JpY2FsDQogICAgICAgICAgICAgICAgICAgICAgICAgICBvcHRpb25hbCwgI25vdCBhIHZhcg0KICAgICAgICAgICAgICAgICAgICAgICAgICAgTUxEbWF4X1JvYmluc29uLCBNTERtZWFuX1JvYmluc29uLCBNTERtaW5fUm9iaW5zb24sICAjcmVwbGFjZWQgYnkgbmV3IHZhcnMNCiAgICAgICAgICAgICAgICAgICAgICAgICAgIE1MRHNkX1JvYmluc29uLCAjbm90IG1lYW5pbmdmdWwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgIFNhbXBJRCkpDQplbnZfY29udDwtZW52X2NvbnQlPiUgbXV0YXRlX2lmKGlzLmludGVnZXIsYXMubnVtZXJpYykNCmVudl9jb3JyIDwtIGVudl9jb250ICMlPiUgc2VsZWN0KC1jKFNhbXBJRCkpDQoNCiMgZW52X2NvcnIkY29vcmRzLngxPC1hcy5udW1lcmljKGVudl9jb3JyJGNvb3Jkcy54MSkNCiMgZW52X2NvcnIkY29vcmRzLngyPC1hcy5udW1lcmljKGVudl9jb3JyJGNvb3Jkcy54MikNCg0KZW52X2NvcnJbKCFpcy5udW1lcmljKGVudl9jb3JyKSksXQ0KYGBgDQoNCiMjIyMgQ29ycmVsYXRpb25zDQpgYGB7cn0NCiMgVmVjdG9yIHRvIGhvbGQgY29ycmVsYXRpb25zDQpjb3JfYXgxIDwtIE5VTEwNCmNvcl9heDIgPC0gTlVMTA0KcHZfYXgxIDwtIE5VTEwNCnB2X2F4MiA8LSBOVUxMDQoNCiMgTk1EUzENCmZvciggaSBpbiBzZXEobGVuZ3RoKGVudl9jb3JyKSkpIHsNCiAgY3QuaSA8LSBjb3IudGVzdChheGlzJE1EUzEsDQogICAgICAgICAgICAgICAgICAgZW52X2NvcnJbLCBpXSwNCiAgICAgICAgICAgICAgICAgICBtZXRob2QgPSAia2VuZGFsbCIpDQogIGNvcl9heDFbaV0gPC0gY3QuaSRlc3RpbWF0ZQ0KICBwdl9heDFbaV0gPC0gY3QuaSRwLnZhbHVlDQp9DQoNCiMgTk1EUzINCmZvciggaSBpbiBzZXEobGVuZ3RoKGVudl9jb3JyKSkpIHsNCiAgY3QuaSA8LSBjb3IudGVzdChheGlzJE1EUzIsDQogICAgICAgICAgICAgICAgICAgZW52X2NvcnJbLCBpXSwNCiAgICAgICAgICAgICAgICAgICBtZXRob2QgPSAia2VuZGFsbCIpDQogIGNvcl9heDJbaV0gPC0gY3QuaSRlc3RpbWF0ZQ0KICBwdl9heDJbaV0gPC0gY3QuaSRwLnZhbHVlDQp9DQoNCmNvcl90YWIgPC0gZGF0YS5mcmFtZShlbnYgPSBuYW1lcyhlbnZfY29yciksDQogICAgICAgICAgICAgICAgICAgICAgb3JkX2F4MSA9IGNvcl9heDEsDQogICAgICAgICAgICAgICAgICAgICAgcHZhbF9heDEgPSBwdl9heDEsDQogICAgICAgICAgICAgICAgICAgICAgb3JkX2F4MiA9IGNvcl9heDIsDQogICAgICAgICAgICAgICAgICAgICAgcHZhbF9heDIgPSBwdl9heDIpDQoNCmNvcl90YWINCg0Kd3JpdGUuY3N2KHggPSBjb3JfdGFiLA0KICAgICAgICAgIGZpbGUgPSBmaWxlLnBhdGgoZGF0YVBhdGgsImlucHV0cy9CYXJlbnRzRGVlcF9jb3ItdGFibGVfcjZfMjAwcmVwX01MRC1iYXRoeS5jc3YiKSwNCi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G9yZCA9IG9yZCwNCiAgICAgICAgICAgICAgICAgICAgICBlbnYudmFyID0gZW52X29zWywgaV0sDQogICAgICAgICAgICAgICAgICAgICAgcHQuc2l6ZSA9IDEsDQogICAgICAgICAgICAgICAgICAgICAgIyBiaW53aWR0aCA9IDAuMDUsDQogICAgICAgICAgICAgICAgICAgICAgdmFyLmxhYmVsID0gbmFtZXMoZW52X29zKVtpXSwNCiAgICAgICAgICAgICAgICAgICAgICBnZW4udGV4dC5zaXplID0gMTAsDQogICAgICAgICAgICAgICAgICAgICAgdGl0bGUudGV4dC5zaXplID0gMTUsDQogICAgICAgICAgICAgICAgICAgICAgbGVnLnRleHQuc2l6ZSA9IDEwKQ0KICANCiAgb3Jkc3Jmc1tbaV1dIDwtIG9zLmkkcGxvdA0KfQ0KDQpvcmRzcmZzX3BsdCA8LSBnZ2FycmFuZ2UocGxvdGxpc3QgPSBvcmRzcmZzLA0KICAgICAgICAgICAgICAgICAgICAgICAgIG5yb3cgPSA1LA0KICAgICAgICAgICAgICAgICAgICAgICAgIG5jb2wgPSA2KQ0KDQpvcmRzcmZzX3BsdA0KYGBgDQojIyMjIyBTYXZlIHNvbWUgb3V0cHV0cw0KYGBge3J9DQpnZ2V4cG9ydChvcmRzcmZzX3BsdCwNCiAgICAgICAgICBmaWxlbmFtZSA9IGZpbGUucGF0aChkYXRhUGF0aCwib3V0cHV0cy9CYXJlbnRzRGVlcF9vcmRpc3VyZnNfdG9wX2NvcnIucG5nIiksDQogICAgICAgICAgd2lkdGggPSAyNTAwLA0KICAgICAgICAgIGhlaWdodCA9IDIwMDApDQoNCmBgYA0KDQoNCiMjIyBTZWwgZW52IHZhciAobWFudWFsKQ0KYGBge3J9DQplbnZfb3NfbSA8LSBlbnZbLGMoIlRtZWFuX1JvYmluc29uIiwgI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAic2FsdF9tYXgiLCAjdG9wIGNvcnINCiAgICAgICAgICAgICAgICAgICJTbWF4X1JvYmluc29uIiwgI2NvbXBhcmlzb24gdG8gdG9wIGNvcnINCiAgICAgICAgICAgICAgICAgICJzd0RlbnNSb2JfYXZzIiwgI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAiQk8yMl9pY2Vjb3Zlcmx0bWF4X3NzIiwjdG9wIGNvcnIgYXgyDQogICAgICAgICAgICAgICAgICAiQk8yMl9pY2Vjb3Zlcm1lYW5fc3MiLCN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgIkJPMjJfZGlzc294bWVhbl9iZG1lYW4iLCN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgIyJCTzIyX2NhcmJvbnBoeXRvbHRtaW5fYmRtZWFuIiwjdG9wIGNvcnIgLSBubyBjbGVhciBncmFkaWVudCBpbiBvcmRpc3VyZg0KICAgICAgICAgICAgICAgICAgIkJPMjJfcHBsdG1pbl9zcyIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgIlgueSIsICNjb21wYXJpc29uIHRvIFkNCiAgICAgICAgICAgICAgICAgICJZIiwgI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAic3BkX3N0ZCIsICN0b3AgY29yciBheDIgKGJsZW5kZWQgbW9kZWwpDQogICAgICAgICAgICAgICAgICAiQ1NwZHNkX1JvYmluc29uIiwgI2NvbXBhcmlzb24gdG8gdG9wIGNvcnIgYXgyIChibGVuZGVkIG1vZGVsKQ0KICAgICAgICAgICAgICAgICAgIm11ZCIsICNoaWdoZXN0IHNlZCB2YXIgYXgxICsgY29ycg0KICAgICAgICAgICAgICAgICAgImdyYXZlbCIsI2hpZ2hlc3Qgc2VkIHZhciBheDEgLSBjb3JyDQogICAgICAgICAgICAgICAgICAiQk8yMl9zaWxpY2F0ZWx0bWF4X2JkbWVhbiIsICNqdXN0IHVuZGVyIHRvcCBjb3JyIGF4MQ0KICAgICAgICAgICAgICAgICAgImJhdGh5IiAjaW50dWl0aXZlIGZvciBjb21wYXJpc29ucw0KICAgICAgICAgICAgICAgICldDQplbnZfb3NfbQ0Kc3RyKGVudl9vc19tKQ0KDQpgYGANCg0KDQojIyMgT3JkaXN1cmZzIG1hbnVhbGx5IHNlbGVjdGVkDQpgYGB7cn0NCm9yZHNyZnNfbSA8LSBsaXN0KGxlbmd0aCA9IG5jb2woZW52X29zX20pKQ0KDQpmb3IgKGkgaW4gc2VxKG5jb2woZW52X29zX20pKSkgew0KICBvcy5pX20gPC0gZ2dfb3JkaXN1cmYob3JkID0gb3JkLA0KICAgICAgICAgICAgICAgICAgICAgIGVudi52YXIgPSBlbnZfb3NfbVssIGldLA0KICAgICAgICAgICAgICAgICAgICAgIHB0LnNpemUgPSAxLA0KICAgICAgICAgICAgICAgICAgICAgICMgYmlud2lkdGggPSAwLjA1LA0KICAgICAgICAgICAgICAgICAgICAgIHZhci5sYWJlbCA9IG5hbWVzKGVudl9vc19tKVtpXSwNCiAgICAgICAgICAgICAgICAgICAgICBnZW4udGV4dC5zaXplID0gMTAsDQogICAgICAgICAgICAgICAgICAgICAgdGl0bGUudGV4dC5zaXplID0gMTUsDQogICAgICAgICAgICAgICAgICAgICAgbGVnLnRleHQuc2l6ZSA9IDEwKQ0KICANCiAgb3Jkc3Jmc19tW1tpXV0gPC0gb3MuaV9tJHBsb3QNCn0NCg0Kb3Jkc3Jmc19wbHRfbSA8LSBnZ2FycmFuZ2UocGxvdGxpc3QgPSBvcmRzcmZzX20sDQogICAgICAgICAgICAgICAgICAgICAgICAgbnJvdyA9IDQsDQogICAgICAgICAgICAgICAgICAgICAgICAgbmNvbCA9IDQpDQoNCm9yZHNyZnNfcGx0X20NCmBgYA0KDQojIyMjIyBTYXZlIHNvbWUgb3V0cHV0cw0KYGBge3J9DQpnZ2V4cG9ydChvcmRzcmZzX3BsdF9tLA0KICAgICAgICAgIGZpbGVuYW1lID0gZmlsZS5wYXRoKGRhdGFQYXRoLCJvdXRwdXRzL0JhcmVudHNEZWVwX29yZGlzdXJmc19tYW5fc2VsX2RvbWVhbi5wbmciKSwNCiAgICAgICAgICB3aWR0aCA9IDIwMDAsDQogICAgICAgICAgaGVpZ2h0ID0gMjAwMCkNCg0KYGBgDQoNCg0KDQoNCiMjIyBFbnZmaXQNCmBgYHtyfQ0KIyMgU2VsZWN0IGlmIGFueSB2YXIgc2hvdWxkIGJlIGV4Y2x1ZGVkIGZyb20gZW52Zml0IChtYWtlcyBsZXNzIGJ1c3kgdG8gcmVhZCkNCmVudl9vc19tX2VudmZpdDwtZW52X29zX20gWyxjKCJUbWVhbl9Sb2JpbnNvbiIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgInNhbHRfbWF4IiwgI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAiU21heF9Sb2JpbnNvbiIsICNjb21wYXJpc29uIHRvIHRvcCBjb3JyDQogICAgICAgICAgICAgICAgICAic3dEZW5zUm9iX2F2cyIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgIkJPMjJfaWNlY292ZXJsdG1heF9zcyIsI3RvcCBjb3JyIGF4Mg0KICAgICAgICAgICAgICAgICAgIyJCTzIyX2ljZWNvdmVybWVhbl9zcyIsI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAiQk8yMl9kaXNzb3htZWFuX2JkbWVhbiIsI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAjIkJPMjJfZGlzc294bHRtaW5fYmRtZWFuIiwjdG9wIGNvcnINCiAgICAgICAgICAgICAgICAgICMiQk8yMl9jYXJib25waHl0b2x0bWluX2JkbWVhbiIsI3RvcCBjb3JyIC0gbm8gY2xlYXIgZ3JhZGllbnQgaW4gb3JkaXN1cmYNCiAgICAgICAgICAgICAgICAgICJCTzIyX3BwbHRtaW5fc3MiLCAjdG9wIGNvcnINCiAgICAgICAgICAgICAgICAgICJYLnkiLCAjY29tcGFyaXNvbiB0byBZDQogICAgICAgICAgICAgICAgICAiWSIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgInNwZF9zdGQiLCAjdG9wIGNvcnIgYXgyIChibGVuZGVkIG1vZGVsKQ0KICAgICAgICAgICAgICAgICAjICJDU3Bkc2RfUm9iaW5zb24iLCAjY29tcGFyaXNvbiB0byB0b3AgY29yciBheDIgKGJsZW5kZWQgbW9kZWwpDQogICAgICAgICAgICAgICAgICAibXVkIiwgI2hpZ2hlc3Qgc2VkIHZhciBheDEgKyBjb3JyDQogICAgICAgICAgICAgICAgICAiZ3JhdmVsIiwjaGlnaGVzdCBzZWQgdmFyIGF4MSAtIGNvcnINCiAgICAgICAgICAgICAgICAgICJCTzIyX3NpbGljYXRlbHRtYXhfYmRtZWFuIiwgI2p1c3QgdW5kZXIgdG9wIGNvcnIgYXgxDQogICAgICAgICAgICAgICAgICAiYmF0aHkiICNpbnR1aXRpdmUgZm9yIGNvbXBhcmlzb25zDQogICAgICAgICAgICAgICAgDQogIA0KKV0NCg0KY29sbmFtZXMoZW52X29zX21fZW52Zml0KTwtYygiVCIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgInNNeCIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgIlNtYXhSIiwgI2NvbXBhcmlzb24gdG8gdG9wIGNvcnINCiAgICAgICAgICAgICAgICAgICJzd0RlbnNSIiwgI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAiaWNlY292bWF4IiwjdG9wIGNvcnIgYXgyDQogICAgICAgICAgICAgICAgICAjImljZWNvdmF2IiwjdG9wIGNvcnINCiAgICAgICAgICAgICAgICAgICJkaXNzb3hhdiIsI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAjImRpc3NveG1pbiIsI3RvcCBjb3JyDQogICAgICAgICAgICAgICAgICAjIkJPMjJfY2FyYm9ucGh5dG9sdG1pbl9iZG1lYW4iLCN0b3AgY29yciAtIG5vIGNsZWFyIGdyYWRpZW50IGluIG9yZGlzdXJmDQogICAgICAgICAgICAgICAgICAicHBsdG1pbiIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgIlgiLCAjY29tcGFyaXNvbiB0byBZDQogICAgICAgICAgICAgICAgICAiWSIsICN0b3AgY29ycg0KICAgICAgICAgICAgICAgICAgInNwZF9zdGQiLCAjdG9wIGNvcnIgYXgyIChibGVuZGVkIG1vZGVsKQ0KICAgICAgICAgICAgICAgICAjICJDU3NkIiwgI2NvbXBhcmlzb24gdG8gdG9wIGNvcnIgYXgyIChibGVuZGVkIG1vZGVsKQ0KICAgICAgICAgICAgICAgICAgIm11ZCIsICNoaWdoZXN0IHNlZCB2YXIgYXgxICsgY29ycg0KICAgICAgICAgICAgICAgICAgImdyYXZlbCIsI2hpZ2hlc3Qgc2VkIHZhciBheDEgLSBjb3JyDQogICAgICAgICAgICAgICAgICAiU2lMdG1heCIsICNqdXN0IHVuZGVyIHRvcCBjb3JyIGF4MQ0KICAgICAgICAgICAgICAgICAgImJhdGh5IiAjaW50dWl0aXZlIGZvciBjb21wYXJpc29ucw0KICAgICAgICAgICAgICAgICApDQoNCiMjIEVudmZvdCBwbG90DQpnZ19lbnZmaXQob3JkID0gb3JkLA0KICAgICAgICAgIGVudiA9IGVudl9vc19tX2VudmZpdCwNCiAgICAgICAgICBwdC5zaXplID0gMSkNCg0KIyMgRW52Zml0IGFuYWx5c2lzDQoNCmVmIDwtIGVudmZpdChvcmQgPSBvcmQsDQogICAgICAgICAgICAgZW52ID0gZW52X29zX21fZW52Zml0LA0KICAgICAgICAgICAgICMgbmEucm0gPSBUUlVFDQogICAgICAgICAgICAgKQ0KZWZERiA8LSBhcy5kYXRhLmZyYW1lKHNjb3JlcyhlZiwNCiAgICAgICAgICAgICAgICAgICAgICAgICAgICAgZGlzcGxheSA9ICJ2ZWN0b3JzIikpDQpgYGANCg0KIyMjIyMgU2F2ZSB0aGUgcGxvdA0KYGBge3J9DQpnZ3NhdmUoZmlsZW5hbWUgPSBmaWxlLnBhdGgoZGF0YVBhdGgsIm91dHB1dHMvQmFyZW50c0RlZXBfRW52Rml0X21hbl9zZWxfY2xuX2RvbWVhbi5wbmciKSwNCiAgICAgICBkZXZpY2UgPSAicG5nIiwNCiAgICA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AgY29vcmRfZml4ZWQoKSArDQogIGdndGl0bGUoIkdOTURTIGNvbG91cmVkIGJ5IGxhbmRzY2FwZSBjbGFzcyIsDQogICAgICAgICAgc3VidGl0bGUgPSAiRmlyc3QgcnVuIikgKw0KICBnZW9tX3BvaW50KGFlcyhjb2xvdXIgPSBmYWN0b3IobGFuZHNjYXBlTmFtZSkpKSArDQogIGdlb21fdmxpbmUoeGludGVyY2VwdCA9IDAsDQogICAgICAgICAgICAgbGluZXR5cGUgPSAyLA0KICAgICAgICAgICAgIGNvbG91ciA9ICJsaWdodGdyYXkiKSArDQogIGdlb21faGxpbmUoeWludGVyY2VwdCA9IDAsDQogICAgICAgICAgICAgbGluZXR5cGUgPSAyLA0KICAgICAgICAgICAgIGNvbG91ciA9ICJsaWdodGdyYXkiKSsNCiAgZ3VpZGVzKGNvbG91cj1ndWlkZV9sZWdlbmQobmNvbD0yKSkNCg0KcF9sYW5kDQpgYGANCg0KDQojIyMjIEdubWRzIHcgZ21vcnBoDQpgYGB7cn0NCg0KcF9nbW8gPC0gZ2dwbG90KGRhdGEgPSBlbnZfdmlzLA0KICAgICAgICAgICAgICAgICAgICAgYWVzKHggPSBnbm1kczEsDQogICAgICAgICAgICAgICAgICAgICAgICAgeSA9IGdubWRzMikpICsNCiAgdGhlbWVfY2xhc3NpYygpICsNCiAgY29vcmRfZml4ZWQoKSArDQogIGdndGl0bGUoIkdOTURTIGNvbG91cmVkIGJ5IGxhbmRzY2FwZSBjbGFzcyIsDQogICAgICAgICAgc3VidGl0bGUgPSAiRmlyc3QgcnVuIikgKw0KICBnZW9tX3BvaW50KGFlcyhjb2xvdXIgPSBmYWN0b3IoZ21vcnBoKSkpICsNCiAgZ2VvbV92bGluZSh4aW50ZXJjZXB0ID0gMCwNCiAgICAgICAgICAgICBsaW5ldHlwZSA9IDIsDQogICAgICAgICAgICAgY29sb3VyID0gImxpZ2h0Z3JheSIpICsNCiAgZ2VvbV9obGluZSh5aW50ZXJjZXB0ID0gMCwNCi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